if exists (select 1 from sysobjects where name = 'set_ferienzeit' and type = 'P')
begin
   drop procedure set_ferienzeit
   print 'Procedure: set_ferienzeit deleted ...'
end
go
create procedure set_ferienzeit(
  @prsid             int           = 1,
  @von               char(8)       = '20070101',--'00000000',
  @bis               char(8)       = '20070105',
  @retval            int           = 0 output
)
as
begin
  set nocount on
  declare    @datumvon    datetime
  declare    @datumbis    datetime
   if @prsid = 0 or @prsid = '' select @prsid = null
   if @von <> '00000000' select @datumvon = convert(datetime, @von, 112)
   if @von <> '00000000' select @datumbis = convert(datetime, @bis, 112)
   if (@prsid is not null)
   begin
      insert into Ferien (PrsId, Von, Bis) values (@prsid, @datumvon, @datumbis)
      
      select @retval = MAX(FerienID)
        from Ferien
       where PrsId = @prsid
         and Von = @von
         and Bis = @bis
      
   end
end
go
print 'Procedure: set_ferienzeit done ...'
go
grant exec on set_ferienzeit to prsadmins with grant option
go
grant exec on set_ferienzeit to prsusers
go

